# -*- coding: utf-8 -*-
"""
2025-05-29
"""

from PySide6.QtCore import Slot, QSize
from PySide6.QtGui import QAction, QKeySequence
from PySide6.QtWidgets import QMainWindow, QApplication, QVBoxLayout, QHBoxLayout, QPushButton, QWidget, QMessageBox, QStackedWidget
from PySide6.QtCore import Qt
from PySide6.QtGui import QGuiApplication, QCloseEvent,QIcon
## from PySide6.QtCore.Qt import 

##from PySide6.QtCore import WindowState

##from top.wardyan.utils import winformutils
from top.wardyan.core.action.baseaction import WMainWindow
from top.wardyan.core.widges.tables import WTableView
from top.wardyan.core.vo.vos import Record, TableCfg, TableColCfg

from top.wardyan.projects.checktool_manager.main.checktool_manager_logon import *
from top.wardyan.projects.checktool_manager.main.checktool_manager_yt_check_view import *
from top.wardyan.projects.checktool_manager.main.checktool_manager_yt_customer_view import *
from top.wardyan.projects.checktool_manager.main.checktool_manager_yt_checkplan_view import *

import os



class ChecktoolManager(WMainWindow):

    table : WTableView = None  # type: ignore
    def __init__(self, name : str = __name__):
        WMainWindow.__init__(self, "ChecktoolManager")
        ## 显示窗体具体信息
        self.main()
    

    def initMenubar(self) :
        HEIGHT = 50

    
    def main(self) :
        self.initMenubar()
        
        # 创建堆叠窗口用于切换不同界面
        self.stacked_widget = QStackedWidget()
        self.check_shell = ChecktoolCheckShell()
        self.customer_shell = ChecktoolCustomerShell()
        self.checkplan_shell = ChecktoolCheckplanShell()
        
        self.stacked_widget.addWidget(self.check_shell)  # 索引0
        self.stacked_widget.addWidget(self.customer_shell)  # 索引1
        self.stacked_widget.addWidget(self.checkplan_shell)  # 索引2
        
        # 创建顶部按钮菜单栏
        menu_widget = QWidget()
        menu_layout = QHBoxLayout()
        menu_widget.setLayout(menu_layout)
        menu_widget.setFixedHeight(60)
        
        # 检查项目按钮
        self.check_btn = QPushButton("检查项目")
        self.check_btn.setFixedHeight(40)
        self.check_btn.clicked.connect(lambda: self.switch_view(0))
        self.check_btn.setStyleSheet("background-color: #007acc; color: white; font-weight: bold;")  # 默认选中样式
        
        # 客户信息按钮
        self.customer_btn = QPushButton("客户信息")
        self.customer_btn.setFixedHeight(40)
        self.customer_btn.clicked.connect(lambda: self.switch_view(1))
        self.customer_btn.setStyleSheet("background-color: #f0f0f0; color: black;")
        
        # 检查项目方案按钮
        self.checkplan_btn = QPushButton("检查项目方案")
        self.checkplan_btn.setFixedHeight(40)
        self.checkplan_btn.clicked.connect(lambda: self.switch_view(2))
        self.checkplan_btn.setStyleSheet("background-color: #f0f0f0; color: black;")
        
        # 添加弹簧使按钮靠左
        menu_layout.addWidget(self.check_btn)
        menu_layout.addWidget(self.customer_btn)
        menu_layout.addWidget(self.checkplan_btn)
        menu_layout.addStretch()
        
        # 创建主布局
        main_widget = QWidget()
        main_layout = QVBoxLayout()
        main_layout.setContentsMargins(0, 0, 0, 0)
        main_layout.setSpacing(0)
        main_widget.setLayout(main_layout)
        
        # 添加菜单栏和堆叠窗口到主布局
        main_layout.addWidget(menu_widget)
        main_layout.addWidget(self.stacked_widget)
        
        self.setCentralWidget(main_widget)
        
        # 默认显示第一个界面
        self.switch_view(0)

    def switch_view(self, index):
        """切换视图"""
        self.stacked_widget.setCurrentIndex(index)
        
        # 更新按钮样式
        if index == 0:
            self.check_btn.setStyleSheet("background-color: #007acc; color: white; font-weight: bold;")
            self.customer_btn.setStyleSheet("background-color: #f0f0f0; color: black;")
            self.checkplan_btn.setStyleSheet("background-color: #f0f0f0; color: black;")
        elif index == 1:
            self.check_btn.setStyleSheet("background-color: #f0f0f0; color: black;")
            self.customer_btn.setStyleSheet("background-color: #007acc; color: white; font-weight: bold;")
            self.checkplan_btn.setStyleSheet("background-color: #f0f0f0; color: black;")
        else:  # index == 2
            self.check_btn.setStyleSheet("background-color: #f0f0f0; color: black;")
            self.customer_btn.setStyleSheet("background-color: #f0f0f0; color: black;")
            self.checkplan_btn.setStyleSheet("background-color: #007acc; color: white; font-weight: bold;")
        


if __name__ == "__main__" :     ## or 1 == 1
    app = QApplication([])
    app.setWindowIcon(QIcon("umbrella.ico"))
    w = ChecktoolManager()
    w.show()
    app.exec()